#include "simulation.h"

void sim_compute_momenta( Simulation *sim )
{
    CHECK_SIM(sim);
    field_compute_momenta(sim->Ju,
                          sim->Jv,
                          sim->rho,
                          sim->u,
                          sim->v);
}

void sim_compute_velocities( Simulation *sim )
{
    CHECK_SIM(sim);
    field_compute_velocities(sim->u,
                             sim->v,
                             sim->rho,
                             sim->Ju,
                             sim->Jv);
}

void sim_compute_divergence(Simulation *sim)
{
	CHECK_SIM(sim);
	field_divergence(sim->dvg, 
					 sim->Ju,
					 sim->Jv,
					 sim->inv_dx,
					 sim->inv_dy); 
}

void sim_compute_divergence_pred(Simulation *sim)
{
	CHECK_SIM(sim);
	field_divergence(sim->dvg,
					 sim->Ju_pred ,
					 sim->Jv_pred,
					 sim->inv_dx,
					 sim->inv_dy);
}

void sim_compute_laplacian( Simulation *sim )
{
	CHECK_SIM(sim);
    field_laplacian(sim->Lrhv,
					sim->Jv,
					sim->inv_dx2,
					sim->inv_dy2);
}

void sim_compute_laplacian_rhu( Simulation *sim )
{
	CHECK_SIM(sim);
    field_laplacian_rhu(sim->Lrhu,
						sim->Ju,
						sim->rho,
						sim->inv_dx2,
						sim->inv_dy2);
}

void sim_compute_laplacian_rhv(Simulation *sim)
{
	CHECK_SIM(sim);
	field_laplacian_rhv(sim->Lrhv, 
						sim->Jv,
						sim->rho,
						sim->inv_dx2, 
						sim->inv_dy2); 
}

void sim_compute_nonlinear(Simulation *sim)
{
	CHECK_SIM(sim);
	field_nonlinear_1(sim->rx, 
					  sim->Ju, 
					  sim->Jv, 
					  sim->rho, 
					  sim->inv_dx, 
					  sim->inv_dy);
	
	field_nonlinear_2(sim->ry,
					  sim->Ju,
					  sim->Jv,
					  sim->rho, 
					  sim->inv_dx,
					  sim->inv_dy); 
	
}
void sim_compute_increment(Simulation *sim)
{
	CHECK_SIM(sim); 
	field_compute_increment(sim->delta_Ju,
							sim->dvg_x,
							sim->gradPx,
							sim->rx);
	
	field_compute_increment(sim->delta_Jv,
							sim->dvg_y,
							sim->gradPy,
							sim->ry);
	
	field_compute_increment_1(sim->delta_Ju1,
							  sim->dvg_x_bis,
							  sim->gradPx,
							  sim->Lrhu,
							  sim->rx,
							  sim->eta);
	
	field_compute_increment_1(sim->delta_Jv1,
							  sim->dvg_y_bis,
							  sim->gradPy,
							  sim->Lrhv,
							  sim->ry,
							  sim->eta);

}

void sim_compute_tension(Simulation *sim)
{
	CHECK_SIM(sim);
	
	field_tension(sim->sigma11,
				  sim->sigma12,
				  sim->sigma22,
				  sim->rho,
				  sim->Ju,
				  sim->Jv,
				  sim->eta1,
				  sim->zeta1,
				  sim->K,
				  sim->inv_dx,
				  sim->inv_dy,
				  sim->inv_dx2, 
				  sim->inv_dy2);
	
	field_tension_bis(sim->sigma11_bis,
					sim->sigma12_bis,
					sim->sigma22_bis,
					sim->rho,
					sim->K,
					sim->inv_dx,
					sim->inv_dy,
					sim->inv_dx2,
					sim->inv_dy2);
	
}

void sim_compute_divergence_tension(Simulation *sim)
{
	CHECK_SIM(sim);
	field_divergence_tenseur1(sim->dvg_x,
							  sim->sigma11,
							  sim->sigma12,
							  sim->inv_dx,
							  sim->inv_dy);
	
	field_divergence_tenseur2(sim->dvg_y,
							  sim->sigma12,
							  sim->sigma22,
							  sim->inv_dx,
							  sim->inv_dy);
	
	field_divergence_tenseur1(sim->dvg_x_bis,
							  sim->sigma11_bis,
							  sim->sigma12_bis,
							  sim->inv_dx,
							  sim->inv_dy);
	
	field_divergence_tenseur2(sim->dvg_y_bis,
							  sim->sigma12_bis,
							  sim->sigma22_bis,
							  sim->inv_dx,
							  sim->inv_dy);
	
}